home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 117 / MacAddict 117.dmg / Software / Internet & Communication / Snak 5.1 (shareware).dmg / Snak.app / Contents / Resources / Scripts / TriviaBot / trivia.txt < prev   
Text File  |  2006-02-01  |  36KB  |  1,197 lines

  1. # IRCII Trivia Script v2.0
  2. # Copyright (c) 2001-2005 Bernard Yen (Seeker on IRC)
  3. # V 1.1.0   Initial release. Created by Bernard Yen.        
  4. # V 2.0     Adapted and updated for Snak 5 by Kent Sorensen. 
  5. #            All support questions for version 2.0 must be sent to kents@snak.com
  6. #            Improved saving.
  7. #            Removed setting of homedir and rmcmd
  8. #            Added mkdir for TriviaScript directory in your home folder
  9. #            Moved trivia.sav file to TriviaScript directory
  10. #            Changed all calls to say to trivsay which uses the -t flag to direct the message to the channel that was active when the script was loaded
  11. #            Removed the need to authenticate, and took out the passwords
  12. #            Questions are answered in the channel
  13. #            Took out storage of wrong answers. This can't be maintained when questions are answered in the channel.
  14. #            The penalties are also gone..
  15. #            Renamed auth_help to update_stats
  16. #            Only one correct answer per question
  17. #            !start no longer required the admin password
  18. #            Removed the duel system as it won't fit the current model
  19. #            Remind user to change admin password on first launch
  20. # --------------------------------------------------------------------------
  21. # This software is provided 'as-is', without any expressed or implied
  22. # warrenty. In no event will the author be held liable for any damages
  23. # arising from the use of this software.
  24. #
  25. # Permissing is granted to anyone to use this software for non-commercial
  26. # purposes and to alter and redistribute it freely, subject to the
  27. # following restrictions:
  28. #
  29. # 1. The origin of this software must not be misrepresented; you must not
  30. # claim that you wrote the original software. If you use this software in
  31. # a product, an acknowledgement in the product documentation is required.
  32. #
  33. # 2. Altered source versions must be plainly marked as such, and must not
  34. # be misrepresented as being the original software
  35. #
  36. # 3. This notice may not be removed or altered from any source distribution.
  37. #
  38. # --------------------------------------------------------------------------
  39.  
  40. # --- Program Constant Declarations ---
  41.  
  42. # Limit on how long each question is posed for in seconds
  43.  
  44. @trivia.LIMIT.1 = 30
  45. @trivia.LIMIT.2 = 25
  46. @trivia.LIMIT.3 = 20
  47. @trivia.LIMIT.4 = 20
  48. @trivia.LIMIT.5 = 20
  49.  
  50. # Number of seconds to pause between questions
  51.  
  52. @trivia.BREAK = 10
  53.  
  54. # Number of seconds to pause between final score and start of wagering. Note that
  55. # the actual time between display of score and wagering start is WAGERWAIT - BREAK
  56. # since both timers are started at the same time.
  57.  
  58. @trivia.WAGERWAIT = 30
  59.  
  60. # Number of seconds to pause between start of wagering and end of wagering.
  61.  
  62. @trivia.WAGERTIME = 30
  63.  
  64. # Number of rounds available in one game, excluding wagering round.
  65.  
  66. @trivia.MAXROUND = 4
  67.  
  68. # Number of questions for each round. Last round must have exactly 1 question.
  69.  
  70. @trivia.QU.1 = 5
  71. @trivia.QU.2 = 5
  72. @trivia.QU.3 = 5
  73. @trivia.QU.4 = 5
  74. @trivia.QU.5 = 1
  75.  
  76. # Maximum number of daily double questions per round.
  77.  
  78. @trivia.SUDDENDEATH = 3
  79.  
  80. # Probability of daily double questions appearing (1/PROBDEATH).
  81.  
  82. @trivia.PROBDEATH = 8
  83.  
  84. # Proportion of regular round's point to give to player if they get daily double questions right.
  85. # The final award is (round's point)*trivia.AWARDDEATH.
  86.  
  87. @trivia.AWARDDEATH = 2
  88.  
  89. # Amount of points awarded for each round. Last round is 0 points since it is the wagering
  90. # round, and people cannot obtain additional points for getting it right.
  91.  
  92. @trivia.P.1 = 1
  93. @trivia.P.2 = 2
  94. @trivia.P.3 = 4
  95. @trivia.P.4 = 8
  96. @trivia.P.5 = 0
  97.  
  98. # Administrative password -- required for all admin commands.
  99.  
  100. @trivia.ADMINPASS = [default]
  101.  
  102. # Valid commands that can be sent to the bot.
  103.  
  104. @trivia.VALIDCMD = [!start !stop !reset !add !sub !wipe !save !title !title_kill]
  105.  
  106. # Valid admin commands that can be sent to the bot.
  107.  
  108. @trivia.VALIDADMINCMD = [!stop !reset !add !sub !wipe !save]
  109.  
  110. # Rank above which player can create their own title.
  111.  
  112. @trivia.MAXRANK = 1000
  113.  
  114. # People who have helped on this project and deserves special mention.
  115.  
  116. @trivia.THANKYOU = [chibi_k, dunno001, Hisoka, InuTrunks, IPChan, Klepto, Knotz, lego, Mike-hime, melz, NFD, Teppei, XObadboy, xxloloxx]
  117.  
  118. # Version of the trivia script.
  119.  
  120. @trivia.VERSION = [2.0]
  121.  
  122. # --- file saving stuff ---
  123.  
  124. # Snak adaptation 1.1.1 make trivia store its file in a subdirectory to home
  125. EVAL /comment $mkdir(${HOME}/TriviaScript)
  126.  
  127. @ trivia.SAVEFILE = [trivia.sav]
  128.  
  129. # --- Channel Name is the active channel when the script was loaded ---
  130. # can be changed later with /triviachannel <channel>
  131. @trivia.channel = [$C]
  132.  
  133. # --- Global Variables ---
  134.  
  135. # People who have answered the current question correctly
  136.  
  137. @trivia.curques = []
  138.  
  139. # Flag indicating whether a game is running (0:NO, 1:YES)
  140.  
  141. @trivia.current = 0
  142.  
  143. # Current trivia round number
  144.  
  145. @trivia.round = 0
  146.  
  147. # Questions remaining in current round
  148.  
  149. @trivia.remaining = 0
  150.  
  151. # Question number of current round being asked
  152.  
  153. @trivia.quesnum = 0
  154.  
  155. # Flag indicating whether there is a question being shown right now
  156.  
  157. @trivia.active = 0
  158.  
  159. # A list of all used questions since the robot has been started
  160.  
  161. @trivia.usedques = []
  162.  
  163. # Flag indicating whether bonus points are given
  164.  
  165. @trivia.bonus = 0
  166.  
  167. # Flag indicating whether wagering is allowed
  168.  
  169. @trivia.wager = 0
  170.  
  171. # Flag to fix problems with the compare function during wagering
  172.  
  173. @trivia.wager_special = 0
  174.  
  175. # Count of the number of sudden death questions which has appeared
  176.  
  177. @trivia.amtdeath = 0
  178.  
  179. # Flag indicating whether current question is a sudden death question
  180.  
  181. @trivia.deathflag = 0
  182.  
  183. # Flag indicating whether the question list is loaded
  184.  
  185. @trivia.qloaded = 0
  186.  
  187. # A question timer to display how fast the players responds to the question
  188.  
  189. @trivia.timer = 0
  190.  
  191. # --- Start of program code. Do not modify anything below this line. ---
  192. alias triviachannel {
  193.     @trivia.channel = [$0]
  194. }
  195.  
  196. alias trivsay {
  197.     say -t $trivia.channel $-
  198. }
  199.  
  200. alias trivia {
  201.     # Load the auxilary question file into memory if not loaded yet.
  202.  
  203.     if (!trivia.qloaded) {
  204.         $loadq()
  205.     }
  206.     
  207.     # Load the saved variables from file.
  208.     
  209.     if (!trivia.stat_loaded) {
  210.         /load -p ${HOME}/TriviaScript/$trivia.SAVEFILE
  211.  
  212.     }
  213.         
  214.     # Check whether a game is currently running. Give an error if there is.
  215.  
  216.     if (trivia.current == 0) {
  217.         @trivia.current = 1
  218.         
  219.         # Print out the trivia header (copyright, thank you note, trivia record holder)
  220.         
  221.         trivsay Trivia v$trivia.VERSION Copyright 2002-2005 by 5Seeker
  222.         trivsay Support questions must be sent to Kent Sorensen - kents@snak.com
  223.         trivsay Type !help for a list of available commands
  224.         trivsay     
  225.         
  226.         if (trivia.ADMINPASS == [default])
  227.         {
  228.             echo Your administrator password has not been changed from 'default'
  229.             echo Please type /adminpass <new password>
  230.         }
  231.  
  232.         
  233.         if (!trivia.bestscore || trivia.bestscore == 0) {
  234.             trivsay Highest Trivia Record:5 None @4 0 point
  235.         }
  236.         {
  237.             if (trivia.bestscore == 1) {
  238.                 trivsay Highest Trivia Record:5 $trivia.bestname @4 1 point
  239.             }
  240.             {
  241.                 trivsay Highest Trivia Record:5 $trivia.bestname @4 $trivia.bestscore points
  242.             }
  243.         }
  244.         
  245.         trivsay     
  246.         
  247.         score
  248.         
  249.         # Initialize the randomizer, clear global variables, and show the first question.
  250.         
  251.         @trivia.correct = 0
  252.         @trivia.round = 0
  253.         @trivia.remaining = 0
  254.         @trivia.quesnum = 0
  255.         @trivia.remaining = 0
  256.         @trivia.active = 0
  257.         @trivia.wager = 0
  258.         @trivia.wager_special = 0
  259.         @trivia.amtdeath = 0
  260.         @trivia.deathflag = 0
  261.         
  262.         @trivia.randomvar = trivia.randomvar + 1
  263.         @trivia.seed = [$time()] + trivia.randomvar
  264.         
  265.         $srand($trivia.seed)
  266.         $show_question()
  267.     }
  268.     {
  269.         trivsay [ERROR] Please wait until the current game ends before starting another
  270.     }
  271. }
  272.  
  273. #     Load or reload the question into memory so it can be used by this script.
  274.  
  275. alias loadq {
  276.     ^load trivia_question.txt
  277. }
  278.  
  279. #     Show a question based on the round number. Higher rounds are more difficult. $0 controls whether the
  280. #     wagering round is on (0:NO, 1:YES).
  281.  
  282. alias show_question {
  283.     # Clear global variables.
  284.     
  285.     @trivia.curques = []
  286.  
  287.     # If no more questions available in this round, move to next round and reset question number.
  288.  
  289.     if (!trivia.remaining) {
  290.         @trivia.quesnum = 1
  291.         @trivia.round= trivia.round + 1
  292.         @trivia.remaining = trivia[QU][$trivia.round]
  293.     }
  294.     {
  295.         @trivia.quesnum = trivia.quesnum + 1
  296.     }
  297.     
  298.     # Set expiration timer for current question. If we are in wagering round, queue up $calc_wager to be called.
  299.     
  300.     if ([$0] == 1) {
  301.         ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /calc_wager
  302.     }
  303.     {
  304.         ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /question_timed_out
  305.     }
  306.  
  307.     # Find the maximum number of question available on the current difficulty level and choose
  308.     # one of them. If the question has been posed already, choose another one.
  309.  
  310.     @trivia.catques = trivia[C][$trivia.round]
  311.     @trivia.pick = rand($trivia.catques) + 1
  312.  
  313.     while ([$match($trivia.round*$trivia.pick $trivia.usedques)]) {
  314.         @trivia.pick = rand($trivia.catques) + 1
  315.     }
  316.  
  317.     # Add question to used question list (format round*quesnum)
  318.  
  319.     ^assign trivia.usedques $trivia.usedques $trivia.round*$trivia.pick
  320.     ^assign trivia.temp $trivia[A][$trivia.round][$trivia.pick]
  321.     ^assign trivia.temp $#trivia.temp
  322.  
  323.     # Potentially make this question a daily double question, but the wagering round cannot
  324.     # be turned into a daily double, so additional checks are done. If the question turns out
  325.     # to be a daily double, we increment $trivia.amtdeath by 1 to keep track.
  326.  
  327.     @trivia.deathflag = 0
  328.  
  329.     if ((trivia.amtdeath < trivia.SUDDENDEATH) && (trivia.round <= trivia.MAXROUND)) {
  330.         if (rand($trivia.PROBDEATH) == 0) {
  331.             @trivia.deathflag = 1
  332.             @trivia.amtdeath = trivia.amtdeath + 1
  333.         }
  334.     }
  335.     @trivia.temptitle = [=== Round $trivia.round Question $trivia.quesnum Time Limit: $trivia[LIMIT][$trivia.round] seconds]
  336.  
  337.     if (!trivia.deathflag) 
  338.     {
  339.         if (trivia[P][$trivia.round] > 0)
  340.         {
  341.             if (trivia[P][$trivia.round] == 1)
  342.             {
  343.                 @trivia.temptitle = trivia.temptitle##[ >>1 point per question<< ===]
  344.             }
  345.             {
  346.                 @trivia.temptitle = trivia.temptitle##[ >>$trivia[P][$trivia.round] points per question<< ===]
  347.             }
  348.         }
  349.         {
  350.             # in the wagering round
  351.             @trivia.temptitle = trivia.temptitle##[ ===]
  352.         }
  353.     } 
  354.     {
  355.         if (trivia[P][$trivia.round] > 0)
  356.         {
  357.             @trivia.tempcalc = trivia.AWARDDEATH * trivia[P][$trivia.round]
  358.             @trivia.temptitle = trivia.temptitle##[ >>DAILY DOUBLE $trivia.tempcalc points per question<< ===]
  359.         }
  360.         {
  361.             @trivia.temptitle = trivia.temptitle##[ >>DAILY DOUBLE<< ===]
  362.         }
  363.     }
  364.     
  365.     trivsay $trivia.temptitle
  366.     ^assign -trivia.temptitle
  367.  
  368.     if ([$0] == 1) {
  369.         trivsay Type 4/msg $N <answer>  to answer wagering question
  370.     }
  371.  
  372.     
  373.     # If the answer is a number (i.e. trivia.Q.R.P.N is defined), don't print out the number of words
  374.     # so people are not confused.
  375.     
  376.     if (trivia[Q][$trivia.round][$trivia.pick][N]) {
  377.         trivsay [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<number\>
  378.     }
  379.     {
  380.         if (trivia.temp == 1) {
  381.             trivsay [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp word\>
  382.         }
  383.         {
  384.             trivsay [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp words\>
  385.         }
  386.     }
  387.     
  388.     # Start the timer so we can record down how fast the players answer the question. Also
  389.     # activate the trivia.active flag to indicate that there is an active question.
  390.     
  391.     @trivia.timer = time()
  392.     @trivia.active = 1
  393. }
  394.  
  395.  
  396. #     This function parses messages that the bot may receive. It processes both commands which begin
  397. #     with a "!" and regular answers. If there are no active question, all msgs are treated as regular
  398. #     text which is not processed (except commands, which are still processed).
  399.  
  400. alias handle_public {
  401.  
  402.     if (word(0 $1-) == [!start]) {
  403.         ^timer 1 /trivia
  404.     }
  405.     {
  406.         if (word(0 $1-) == [!help]) {
  407.             #     Help system which private notices a help menu to people who type !help in the channel.
  408.             ^notice $0 Please type 4/msg $N !help <topic> to receive help on specific topics:
  409.             ^notice $0 01. General info: copyright, general, start_game
  410.             ^notice $0 02. Special features: daily_double
  411.             ^notice $0 03. Stat related: title, title_kill
  412.             ^notice $0 04. Admin control: add, reset, save, start, stop, sub, wipe
  413.         }
  414.         {
  415.             if (!trivia.active) {
  416.                 # Normal message, don't do anything.
  417.             }
  418.             {
  419.                 # If it is the wagering round but they don't have points, they are not allowed to answer.
  420.                     
  421.                 if ((trivia.round == (trivia.MAXROUND + 1)) && !trivia[SCORE][$encode($0)]) {
  422.                     ^notice $0 [ERROR] You need at least 1 point to answer in the wagering round.
  423.                 }
  424.                 {
  425.                     # Check the real answer. 
  426.                     $compare($0 $1-)
  427.                 }
  428.             }
  429.             
  430.         }
  431.     }
  432. }
  433.  
  434. #     Handles commands embedded in the incoming private messages. If the command requires special
  435. #     authorization, this function checks the admin password before passing the command on to
  436. #     $parse_admin().
  437.  
  438. alias handle_private {
  439.  
  440.     # Parsing of wagering messages.
  441.     if (trivia.wager && word(0 $1-) == [!wager]) {
  442.         # Check to make sure there is a valid wager, meaning $2 exist and is a positive integer. We also
  443.         # check whether the player has enough points.
  444.         
  445.         @trivia.temp = strip(abcdefghijklmnopqrstuvwxyz. $tolower($2))
  446.         
  447.         if (!trivia.temp || trivia.temp <= 0 || trivia.temp > trivia[SCORE][$encode($0)]) {
  448.             ^notice $0 [ERROR] Command is !wager <amount> where amount more than 0 but less than your score.
  449.         }
  450.         {
  451.             if (trivia.temp == 1) {
  452.                 ^notice $0 You have chosen to wager5 $trivia.temp point.
  453.             }
  454.             {
  455.                 ^notice $0 You have chosen to wager5 $trivia.temp points.
  456.             }
  457.             
  458.             # This is a validated wager, so go ahead and place it (exits function).
  459.             
  460.             $putwager($0 $trivia.temp)
  461.         }
  462.     }
  463.  
  464.     # Determine whether they are messaging a valid command. If so, go to command parsing.
  465.     # Otherwise, go to message parsing.
  466.  
  467.     if (match($word(0 $1-) $trivia.VALIDCMD)) 
  468.     {        
  469.         # !title, !title_kill are used for the personal stat system.
  470.                     
  471.         if (word(0 $1-) == [!title]) {
  472.             @trivia.tempnet = trivia[SCORE][$encode($0)]
  473.             
  474.             if (trivia.tempnet < trivia.MAXRANK) {
  475.                 ^notice $0 [ERROR] Sorry, but your rank is not high enough to use this command.
  476.             }
  477.             {
  478.                 if (!word(1 $1-)) {
  479.                     ^notice $0 [ERROR] Command is !title <new title>.
  480.                 }
  481.                 {
  482.                     ^timer 1 /change_title $0 $2-
  483.                 }
  484.             }
  485.         }
  486.  
  487.         if (word(0 $1-) == [!title_kill]) {
  488.             if (trivia[SELF_TITLE][$encode($0)] != []) {
  489.                 ^assign -trivia[SELF_TITLE][$encode($0)]
  490.                 ^notice $0 Your customized title has been successfully removed.
  491.             }
  492.             {
  493.                 ^notice $0 [ERROR] Sorry, but you do not have a customized title to delete.
  494.             }
  495.         }
  496.         
  497.         if (word(0 $1-) == [!start]) {
  498.             ^timer 1 /trivia
  499.         }
  500.         
  501.  
  502.         # !stop, !reset, !add, !sub, !wipe are admin cmds which require the
  503.         # admin password. Do not put non-admin commands below here because the admin password is
  504.         # checked at this point. Normal commands will fail.
  505.         
  506.         if (!match($word(0 $1-) $trivia.VALIDADMINCMD)) {
  507.             # Don't do anything since this is not an admin command.
  508.         }
  509.         {
  510.             if (word(1 $1-) != trivia.ADMINPASS) {
  511.                 ^notice $0 [ERROR] The admin password you provided is not correct.
  512.             }
  513.             {
  514.                 $parse_admin($0 $1-)
  515.             }
  516.         }
  517.     }
  518.     {
  519.         if (word(0 $1-) == [!help]) {
  520.         
  521.             if (word(1 $1-) == [copyright]) {
  522.                 ^notice $0 The full content of this script as well auxilary support files are copyrights of Bernard Yen. You are allowed to modify and distribute the script on a non-profit basis, but changes must be clearly stated and not misrepresented as the original.
  523.             }
  524.  
  525.             if (word(1 $1-) == [general]) {
  526.                 ^notice $0 There are $trivia.MAXROUND rounds every game, followed by a wagering round where you can potentially double your score. Points are allocated as $trivia.P.1, $trivia.P.2, $trivia.P.3, and $trivia.P.4 respectively for the $trivia.MAXROUND rounds. Approximately 2 questions per game are daily double questions that carry greater award. To answer, simply type the answer in the channel.
  527.             }
  528.         
  529.             if (word(1 $1-) == [start_game]) {
  530.                 ^notice $0 You can start a game of trivia at any time by typing !trivia start into the trivia channel, but please note that only an admin can stop the game while it is in progress.
  531.             }
  532.  
  533. # Special features help system
  534.  
  535.             if (word(1 $1-) == [daily_double]) {
  536.                 ^notice $0 Every game, there are approximately 2 questions that will have "daily double" after them. Getting those correct will give you double the normal points, but getting them incorrect will cause you to lose half of what the round is worth. If the round is normally worth 2 points, you could potentially gain 4 points or lose 2 points per guess.
  537.             }
  538.  
  539. # Stat commands help system
  540.  
  541.             if (word(1 $1-) == [title]) {
  542.                 ^notice $0 By typing /msg $N !title <title> after you reach a rank of at least $trivia.MAXRANK, you will be able to create a customized title for your personal stat database display.
  543.             }
  544.  
  545.             if (word(1 $1-) == [title_kill]) {
  546.                 ^notice $0 By typing /msg $N !title_kill you can delete your customized title.
  547.             }
  548.  
  549.     # Admin control help system
  550.             if (word(1 $1-) == [add]) {
  551.                 ^notice $0 By typing /msg $N !add <adm_pass> <nick> <pts> you can add points to a specified player.
  552.             }
  553.  
  554.             if (word(1 $1-) == [reset]) {
  555.                 ^notice $0 By typing /msg $N !reset <adm_pass> you can reset the used question list.
  556.             }
  557.  
  558.             if (word(1 $1-) == [save]){
  559.                 ^notice $0 By typing /msg $N !save <adm_pass> you can save trivia variables to the file. Please note that this is currently buggy and may cause unexpected crashes.
  560.             }
  561.  
  562.             if (word(1 $1-) == [start]) {
  563.                 ^notice $0 By typing !start in the channel you can start a game of trivia if it is stopped.
  564.             }
  565.  
  566.             if (word(1 $1-) == [stop]) {
  567.                 ^notice $0 By typing /msg $N !stop <adm_pass> you can stop a game of trivia.
  568.             }
  569.  
  570.             if (word(1 $1-) == [sub]) {
  571.                 ^notice $0 By typing /msg $N !sub <adm_pass> <nick> <pts> you can subtract points from a specified player.
  572.             }
  573.  
  574.             if (word(1 $1-) == [wipe]) {
  575.                 ^notice $0 By typing /msg $N !wipe <adm_pass> <nick> where nick is a case sensitive nickname, you can wipe the personal stat database of the specified player.
  576.             }
  577.         }
  578.         {
  579.             # is this a valid answer
  580.             $compare($0 $1-)
  581.         }
  582.     }
  583. }
  584.  
  585. #     Changes the title of an individual player. This function is assumed only accessible after a
  586. #     player achieves the minimum rank of trivia.MAXRANK.
  587.  
  588. alias change_title {
  589.     ^assign trivia[SELF_TITLE][$encode($0)] $1-
  590.     ^notice $0 Your title has been successfully changed.
  591. }
  592.  
  593. #     Handles the parsing of admin commands. This function assumes that when it is being called, the
  594. #     admin password has already been verified.
  595.  
  596. alias parse_admin {
  597.     if (word(0 $1-) == [!stop]) {
  598.         /endtrivia
  599.     }
  600.  
  601.     if (word(0 $1-) == [!reset]) {
  602.         ^timer 1 /reset_used $0
  603.     }
  604.  
  605.     if (word(0 $1-) == [!wipe]) {
  606.         if (!word(2 $1-)) {
  607.             ^notice $0 [ERROR] Command is !wipe <admin password> <nick>.
  608.         }
  609.         {
  610.             ^timer 1 /wipe_stat $0 $word(2 $1-)
  611.         }
  612.     }
  613.  
  614.     if (word(0 $1-) == [!save]) {
  615.         /sve
  616.         ^notice $0 The current game stats have been saved.
  617.     }
  618.  
  619.     if (word(0 $1-) == [!add]) {
  620.         if (!word(2 $1-) || !word(3 $1-)) {
  621.             ^notice $0 [ERROR] Command is !add <password> <nick> <amt>.
  622.         }
  623.         {
  624.             ^assign trivia.tempmsg $0
  625.             ^assign trivia.temppts $word(3 $1-)
  626.             ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0
  627.             ^userhost $word(2 $1-) -cmd if ([$3]){
  628.                 ^timer 1 /add_score $trivia.tempmsg $trivia.tempadd $trivia.temppts
  629.             }
  630.             {
  631.                 ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server.
  632.             }
  633.         }
  634.     }
  635.     
  636.     if (word(0 $1-) == [!sub]) {
  637.         if (!word(2 $1-) || !word(3 $1-)) {
  638.             ^notice $0 [ERROR] Command is !sub <password> <nick> <amt>.
  639.         }
  640.         {
  641.             ^assign trivia.tempmsg $0
  642.              ^assign trivia.temppts $word(3 $1-)
  643.             ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0
  644.             ^userhost $word(2 $1-) -cmd if ([$3]){
  645.                 ^timer 1 /sub_score $trivia.tempmsg $trivia.tempadd $trivia.temppts
  646.             }
  647.             {
  648.                 ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server.
  649.             }
  650.         }
  651.     }
  652. }
  653.  
  654. #     Completely wipes a player's personal stat database. The first parameter is the person who invoked
  655. #     this function, and the second parameter is the nickname to wipe.
  656.  
  657. alias wipe_stat {
  658.     # Load the stat file if not loaded yet.
  659.     
  660.     if (!trivia.stat_loaded) {
  661.         /load -p ${HOME}/TriviaScript/$trivia.SAVEFILE
  662.     }
  663.     
  664.     # Don't let admins wipe stat during a game, or else weird things might happen.
  665.         
  666.     if (trivia.current) {
  667.         ^notice $0 [ERROR] You cannot use the !wipe command when a game is running.
  668.     }
  669.     {
  670.         ^assign -trivia[SCORE][$encode($1)]
  671.         ^notice $0 $1's personal stat database has been successfully wiped.
  672.     }
  673. }
  674.  
  675.  
  676. #     Increase the score of player $1 by $2 points.
  677.  
  678. alias add_score {
  679.     @trivia.temp = [$2]
  680.  
  681.     if (trivia[SCORE][$encode($1)]) {
  682.         @trivia[SCORE][$encode($1)] = trivia[SCORE][$encode($1)] + trivia.temp
  683.     }
  684.     {
  685.         @trivia[SCORE][$encode($1)] = trivia.temp
  686.     }
  687.     
  688.     ^notice $0 $1's score has been successfully changed.
  689. }
  690.  
  691. #     Decrease the score of player $0 by $1 points.
  692.  
  693. alias sub_score {
  694.     @trivia.temp = [$2]
  695.     @trivia[SCORE][$encode($1)] = trivia[SCORE][$encode($1)] - trivia.temp
  696.     
  697.     ^notice $0 $1's score has been successfully changed.
  698.     
  699. }
  700.  
  701. #     Place the wager for the player by assigning it to $trivia[WAGER][$encode($0)].
  702.  
  703. alias putwager {
  704.     @trivia[WAGER][$encode($0)] = [$1]
  705. }
  706.  
  707. #     Because the normal match procedure only matches one word, the match_all procedure is used
  708. #     to match all words.
  709. alias match_all {
  710.     @trivia.counter = 0
  711.     @function_return = 1
  712.  
  713.     # Determine which answer to use
  714.     
  715.        @trivia.temp = trivia[A][$trivia.round][$trivia.pick]
  716.  
  717.     while (trivia.counter < [$#trivia.temp]) {
  718.         # Perform some generic pattern matching with pluaral and non-plural words.
  719.     
  720.         @trivia.tempword = word($trivia.counter $trivia.temp)
  721.  
  722.         if (right(1 $trivia.tempword) == [s] && right(3 $trivia.tempword) != [ies]) {
  723.             @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword)
  724.            }
  725.         {
  726.             if (right(1 $trivia.tempword) == [y]) {
  727.                 @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword)##[ies]
  728.             }
  729.                {
  730.                 if (right(3 $trivia.tempword) == [ies]) {
  731.                     @trivia.tempword2 = left(${@trivia.tempword - 3} $trivia.tempword)##[y]
  732.                 }
  733.                 {
  734.                        @trivia.tempword2 = trivia.tempword##[s]
  735.                 }
  736.             }
  737.         }
  738.         
  739.         # Perform some common typo matching between 'e' and 'i', 'l' and 'r', 'k' and 'c', 'j' and 'z', 'h' and 'u', 'o' and 'u'.
  740.         
  741.         @trivia.guessn1 = strip(ei $1-)
  742.         @trivia.guessn2 = strip(lr $1-)
  743.         @trivia.guessn3 = strip(kc $1-)
  744.         @trivia.guessn4 = strip(jz $1-)
  745.         @trivia.guessn5 = strip(hu $1-)
  746.         @trivia.guessn6 = strip(ou $1-)
  747.         
  748.         @trivia.ansn1 = strip(ei $trivia.tempword)
  749.         @trivia.ansn2 = strip(lr $trivia.tempword)
  750.         @trivia.ansn3 = strip(kc $trivia.tempword)
  751.         @trivia.ansn4 = strip(jz $trivia.tempword)
  752.         @trivia.ansn5 = strip(hu $trivia.tempword)
  753.         @trivia.ansn6 = strip(ou $trivia.tempword)
  754.         
  755.         if (![$match($trivia.tempword $1-)] && ![$match($trivia.tempword2 $1-)] && ![$match($trivia.ansn1 $trivia.guessn1)] && ![$match($trivia.ansn2 $trivia.guessn2)] && ![$match($trivia.ansn3 $trivia.guessn3)] && ![$match($trivia.ansn4 $trivia.guessn4)] && ![$match($trivia.ansn5 $trivia.guessn5)] && ![$match($trivia.ansn6 $trivia.guessn6)]) {
  756.             @function_return = 0
  757.         }
  758.         
  759.         @trivia.counter = trivia.counter + 1
  760.     }
  761. }
  762.  
  763. #     Given the question number, this compares the inputted answer with the correct answer
  764. #     using pattern matching. This function also performs score keeping.
  765.  
  766. alias compare {
  767.     @trivia.finalscore = 0
  768.     @trivia.correct = match_all(0 $1-)
  769.  
  770.     # If correct answer and they have not answered already.
  771.  
  772.     if (trivia.correct){
  773.         if (![$match($0 $trivia.curques)]) {
  774.                         
  775.             # Assign person to people who have already answered the current question correctly.
  776.             ^assign trivia.curques $trivia.curques $0
  777.  
  778.             # update scores if this is a normal round
  779.             if (trivia.round <= trivia.MAXROUND)
  780.             {
  781.                 # Initiate a personal score variable. We must encode the text since some of the
  782.                 # characters in a nickname cannot be part of a variable. If the variable already exists
  783.                 # then add the scores on. We also add the encoded text to a global list so we can remove
  784.                 # all the variables in the end.
  785.  
  786.                 ^assign trivia.finalscore $trivia[P][$trivia.round]
  787.                 
  788.                 # If the question is sudden death, increase the score the player receive, include the bonus
  789.                 # points incurred.
  790.                 
  791.                 if (trivia.deathflag) 
  792.                 {
  793.                     @trivia[SCORE][$encode($0)] = trivia[SCORE][$encode($0)] + trivia.AWARDDEATH * trivia.finalscore
  794.                 }
  795.                 {
  796.                     @trivia[SCORE][$encode($0)] = trivia[SCORE][$encode($0)] + trivia.finalscore
  797.                 }
  798.  
  799.                 
  800.                 if (trivia[SCORE][$encode($0)] > 1)
  801.                 {
  802.                     trivsay Check out the big brain on $0 ! New score $trivia[SCORE][$encode($0)] points !
  803.                 }
  804.                 {
  805.                     trivsay Way to go $0 ! Welcome to the game. You now have $trivia[SCORE][$encode($0)] point !
  806.                 }
  807.                 
  808.                 new_question
  809.             }
  810.         }
  811.         {
  812.             # If they answered the question already
  813.  
  814.             ^notice $0 [ERROR] You have already answered this trivia question!
  815.         }
  816.     }
  817. }
  818.  
  819.  
  820. #     Stops the current trivia challenge round and begin a new one after specified break time.
  821.  
  822. alias question_timed_out {
  823.     trivsay === Round $trivia.round Question $trivia.quesnum Time Limit Expired ===
  824.     trivsay The answer was4 $toupper($trivia[A][$trivia.round][$trivia.pick]).
  825.         
  826.     new_question
  827. }
  828.  
  829. #     begin a new round
  830.  
  831. alias new_question {
  832.  
  833.     ^timer -delete 1
  834.  
  835.     # Decrease the remaining question by one.
  836.  
  837.     @trivia.remaining = trivia.remaining - 1
  838.  
  839.     # If we are in final round and there is no more question, announce the final scores and go into
  840.     # wagering mode. Otherwise set up a timer to show the next question.
  841.  
  842.     ^timer -delete 2
  843.  
  844.     if ((trivia.round == trivia.MAXROUND) && (trivia.remaining == 0)) {
  845.         ^timer -delete 3
  846.         
  847.         ^timer -refnum 3 $trivia.BREAK /score
  848.         ^timer -refnum 2 $trivia.WAGERWAIT /start_wager
  849.         @trivia.active = 0
  850.     }
  851.     {
  852.         
  853.         ^timer -refnum 2 $trivia.BREAK /show_question
  854.     }
  855.  
  856.     @trivia.active = 0
  857. }
  858.  
  859.  
  860.  
  861. #     Start the wagering process by announcing the start of wagering and waiting $trivia.WAGERTIME.
  862.  
  863. alias start_wager {
  864.     @trivia.wager = 1
  865.     @trivia.round = trivia.MAXROUND + 1
  866.     @trivia.remaining = 1
  867.     @trivia.quesnum = 0
  868.     
  869.     trivsay === Wagering Round For $trivia.channel Trivia ===
  870.     trivsay To wager,4 /msg $N !wager <amount> where amount is less than or equal to your total score.
  871.     trivsay You have4 $trivia.WAGERTIME seconds to place your wagers if you choose to participate.
  872.     
  873.     ^timer -refnum 5 $trivia.WAGERTIME /stop_wager
  874. }
  875.  
  876. #     Stops the wagering process by dropping the wager flag and showing the final question.
  877.  
  878. alias stop_wager {
  879.     # Special form of $show_question causing the timer to call $calc_wager() when the timer expires
  880.     # instead of the regular $stop().
  881.     
  882.     @trivia.wager = 0
  883.     @trivia.wager_special = 1
  884.     $show_question(1)
  885. }
  886.  
  887. #     Clear out the used question list.
  888.  
  889. alias reset_used {
  890.     @trivia.usedques = []
  891.     ^notice $0 The used question list has been reset successfully.
  892. }
  893.  
  894.  
  895. #     Terminate the trivia program. ($0 == 1 means normal quit; $0 == 0 means abnormal)
  896.  
  897. alias endtrivia {
  898.     @trivia.winnerscore = 0
  899.  
  900.     if (![$0]) {
  901.         trivsay Trivia terminated at administator request.
  902.         
  903.         foreach trivia.SCORE ii {
  904.             ^assign -trivia[WAGER][$ii]
  905.         }
  906.     }
  907.     {
  908.         # Clear out all player scores according to the global record list. Print out all
  909.         # the scores, and delete the score variables.
  910.         
  911.         trivsay === Final Results For $trivia.channel Trivia ===
  912.         
  913.         foreach trivia.SCORE ii {
  914.             
  915.             # Update the top trivia record if the old one has been broken
  916.             
  917.             if (trivia[SCORE][$ii] > trivia.bestscore) {
  918.                 @trivia.bestscore = trivia[SCORE][$ii]
  919.                 @trivia.bestname = decode($ii)
  920.             }
  921.                         
  922.             # Determine the top score of this game
  923.             
  924.             if (trivia[SCORE][$ii] > trivia.winnerscore) {
  925.                 @trivia.winnerscore = trivia[SCORE][$ii]
  926.             }
  927.         }
  928.         
  929.         score
  930.         
  931.         # clean up
  932.         
  933.         foreach trivia.SCORE ii {            
  934.             ^assign -trivia[WAGER][$ii]
  935.         }
  936.     }
  937.     
  938.     # Clear out all the global variables and timers so weird things don't happen.
  939.     
  940.     if (trivia.active) 
  941.     {
  942.         ^timer -delete 1
  943.     }
  944.     {
  945.         ^timer -delete 2
  946.     }
  947.     
  948.     @trivia.current = 0
  949.  
  950.     trivsay === Type !start to start another round of trivia ===
  951. }
  952.  
  953. #     Calculate the wager results based on what players wagered.
  954.  
  955. alias calc_wager {
  956.     @trivia.active = 0
  957.  
  958.     trivsay === Wagering round is over ===
  959.     trivsay The answer was4 $toupper($trivia[A][$trivia.round][$trivia.pick]).
  960.     
  961.     @trivia.wager_result = []
  962.         
  963.     foreach trivia.SCORE ii {
  964.         
  965.         # If they got the wagering question correct, add the wager. Otherwise, subtract it.
  966.         
  967.         if (trivia[WAGER][$ii]) {
  968.             if (match($decode($ii) $trivia.curques)) {
  969.                 @trivia[SCORE][$ii] = trivia[SCORE][$ii] + trivia[WAGER][$ii]
  970.                 @trivia.wager_result = trivia.wager_result##[4 $decode($ii) won $trivia[WAGER][$ii] points ]
  971.             }
  972.             {
  973.                 @trivia[SCORE][$ii] = trivia[SCORE][$ii] - trivia[WAGER][$ii]
  974.                 @trivia.wager_result = trivia.wager_result##[4 $decode($ii) lost $trivia[WAGER][$ii] points ]
  975.             }
  976.         }
  977.     }
  978.     
  979.     trivsay $trivia.wager_result
  980.     
  981.     $endtrivia(1)
  982. }
  983.  
  984.  
  985. #     Prints out the score of each player whose score is non-zero.
  986.  
  987. alias score {
  988.  
  989.     @trivia.temp = [Current Scores: ]
  990.     
  991.     foreach trivia.SCORE ii {
  992.         if (trivia[SCORE][$ii] == 1 || trivia[SCORE][$ii] == 0) {
  993.             @trivia.temp = trivia.temp##[4 $decode($ii) $trivia[SCORE][$ii] point]
  994.         }
  995.         {
  996.             @trivia.temp = trivia.temp##[4 $decode($ii) $trivia[SCORE][$ii] points] 
  997.         }
  998.     }
  999.     trivsay $trivia.temp
  1000. }
  1001.  
  1002.  
  1003. #     Checks to see whether $0 has any points. If so, we move all those points to $1 and delete
  1004. #     the original record. Otherwise, just ignore the event.
  1005.  
  1006. alias update_name {
  1007.  
  1008.     # Process nickname change only if they have score ≠ 0
  1009.     
  1010.     if (trivia[SCORE][$encode($0)]) {
  1011.         # Transfer points over to new nick
  1012.         
  1013.         @trivia[SCORE][$encode($1)] = trivia[SCORE][$encode($0)]
  1014.         
  1015.         # Delete old nick so it's not displayed
  1016.         
  1017.         ^assign -trivia[WAGER][$encode($0)]
  1018.         ^assign -trivia[SCORE][$encode($0)]
  1019.     }
  1020. }
  1021.  
  1022. #     Converts a given amount of questions into an appropriate title
  1023.  
  1024. alias q_to_title {
  1025.     # If they have own title and rank is high enough, use that instead
  1026.     
  1027.     @trivia.tempnet = trivia[SCORE][$encode($1)] 
  1028.     
  1029.     if (trivia[SELF_TITLE][$encode($1)] != [] && trivia.tempnet >= trivia.MAXRANK) {
  1030.         @function_return = [6$trivia[SELF_TITLE][$encode($1)]]
  1031.     }
  1032.     {
  1033.         if ([$0] < 0) { @function_return = [Court Jester] } {
  1034.         if ([$0] < 10) { @function_return = [Lowly Slime Mold] } {
  1035.         if ([$0] < 20) { @function_return = [Growing Slime Mold] } {
  1036.         if ([$0] < 30) { @function_return = [Regular Slime Mold] } {
  1037.         if ([$0] < 40) { @function_return = [Strong Slime Mold] } {
  1038.         if ([$0] < 50) { @function_return = [Slime Mold Master] } {
  1039.         if ([$0] < 60) { @function_return = [Smelly Fungus] } {
  1040.         if ([$0] < 70) { @function_return = [Fresh Fungus] } {
  1041.         if ([$0] < 80) { @function_return = [Kawaii Fungus] } {
  1042.         if ([$0] < 90) { @function_return = [Buffy Fungus] } {
  1043.         if ([$0] < 100) { @function_return = [Fungus Master] } {
  1044.         if ([$0] < 110) { @function_return = [Weak Peon] } {
  1045.         if ([$0] < 120) { @function_return = [Confused Peon] } {
  1046.         if ([$0] < 130) { @function_return = [Ordinary Peon] } {
  1047.         if ([$0] < 140) { @function_return = [Cheerful Peon] } {
  1048.         if ([$0] < 150) { @function_return = [Powerful Peon] } {
  1049.         if ([$0] < 160) { @function_return = [Poor Mercenary] } {
  1050.         if ([$0] < 170) { @function_return = [Lower Class Mercenary] } {
  1051.         if ([$0] < 180) { @function_return = [Middle Class Mercenary] } {
  1052.         if ([$0] < 190) { @function_return = [Upper Class Mercenary] } {
  1053.         if ([$0] < 200) { @function_return = [Mercenary Guildmaster] } {
  1054.             @function_return = q_to_title_2($0)
  1055.         }}}}}}}}}}}}}}}}}}}}}}
  1056. }
  1057.  
  1058. #     Converts a given amount of questions into an appropriate title
  1059.  
  1060. alias q_to_title_2 {
  1061.         if ([$0] < 210) { @function_return = [Apprentice Footman] } {
  1062.         if ([$0] < 220) { @function_return = [Advancing Footman] } {
  1063.         if ([$0] < 230) { @function_return = [Skilled Footman] } {
  1064.         if ([$0] < 240) { @function_return = [Advanced Footman] } {
  1065.         if ([$0] < 250) { @function_return = [Footman Squad Leader] } {
  1066.         if ([$0] < 260) { @function_return = [Unwieldly Thief] } {
  1067.         if ([$0] < 270) { @function_return = [Average Thief] } {
  1068.         if ([$0] < 280) { @function_return = [Skilled Thief] } {
  1069.         if ([$0] < 290) { @function_return = [Very Stealthy Thief] } {
  1070.         if ([$0] < 300) { @function_return = [Master Shadow Thief] } {
  1071.         if ([$0] < 310) { @function_return = [Weak Archer] } {
  1072.         if ([$0] < 320) { @function_return = [Copper Archer] } {
  1073.         if ([$0] < 330) { @function_return = [Silver Archer] } {
  1074.         if ([$0] < 340) { @function_return = [Gold Archer] } {
  1075.         if ([$0] < 350) { @function_return = [Platinum Archer] } {
  1076.         if ([$0] < 360) { @function_return = [Practicing Knight] } {
  1077.         if ([$0] < 370) { @function_return = [Trained Knight] } {
  1078.         if ([$0] < 380) { @function_return = [Skillful Knight] } {
  1079.         if ([$0] < 390) { @function_return = [Silver Knight] } {
  1080.         if ([$0] < 400) { @function_return = [Golden Knight] } {
  1081.             @function_return = [6God of Trivia]
  1082.     }}}}}}}}}}}}}}}}}}}}
  1083. }
  1084.  
  1085.  
  1086. #     Shutdown routine for the bot. This will save the critical variables and then quit IRC.
  1087.  
  1088. alias shutdown {
  1089.     /sve
  1090.     /quit
  1091. }
  1092.  
  1093. alias adminpass {
  1094.     @trivia.ADMINPASS = [$0]
  1095.     echo Your administrator password has been changed
  1096.     sve
  1097. }
  1098.  
  1099. #     Save routine for storing various statistical variables for the trivia script. This
  1100. #     routine has been adapted from the PurePak script. Credit is hereby given.
  1101.  
  1102. alias sve {
  1103.  
  1104.     foreach trivia.SCORE ii {
  1105.         # Update the top trivia record if the old one has been broken
  1106.         
  1107.         if (trivia[SCORE][$ii] > trivia.bestscore) {
  1108.             @trivia.bestscore = trivia[SCORE][$ii]
  1109.             @trivia.bestname = decode($ii)
  1110.         }
  1111.     }
  1112.  
  1113.  
  1114.     @ LF = [${HOME}/TriviaScript/$trivia.SAVEFILE]
  1115.     
  1116.     @ res = delete($LF)
  1117.     
  1118.     @ FHANDLE = open($LF w)
  1119.         
  1120.     if (FHANDLE > 0)
  1121.     {
  1122.         @res = write( $FHANDLE # Trivia version $trivia.VERSION saved settings file )
  1123.         @res = write( $FHANDLE # Written $stime($time()) )
  1124.         @res = write( $FHANDLE # )
  1125.         
  1126.         @res = write( $FHANDLE @ trivia[ADMINPASS] = [$trivia[ADMINPASS]] )
  1127.  
  1128.         @res = write( $FHANDLE # Flag to indicate loading of stat file )
  1129.         @res = write( $FHANDLE @ trivia[stat_loaded] = [1])
  1130.  
  1131.         @res = write( $FHANDLE # Random seeding value )
  1132.         @res = write( $FHANDLE @ trivia[randomvar] = [$trivia[randomvar]] )
  1133.  
  1134.         @res = write( $FHANDLE # Top trivia score holder )
  1135.         @res = write( $FHANDLE @ trivia[bestname] = [$trivia[bestname]] )
  1136.         @res = write( $FHANDLE @ trivia[bestscore] = [$trivia[bestscore]] )
  1137.                 
  1138.         @res = write( $FHANDLE # Number of points the player has )
  1139.         foreach trivia.SCORE ii { @res = write( $FHANDLE @trivia.SCORE.$ii = [$trivia.SCORE[$ii]] )}
  1140.         
  1141.         @res = write( $FHANDLE # Customized titles for players )
  1142.         foreach trivia.SELF_TITLE ii { @res = write( $FHANDLE @trivia.SELF_TITLE.$ii = [$trivia.SELF_TITLE[$ii]] )}
  1143.  
  1144.         @res = write( $FHANDLE echo *** Saved settings loaded from $LF )
  1145.  
  1146.         @res = close( $FHANDLE )
  1147.         
  1148.         echo *** Current settings saved to $LF
  1149.     }
  1150.     {
  1151.         echo *** Could not open $LF !
  1152.     }
  1153.     ^assign -res
  1154.     ^assign -FHANDLE
  1155. }
  1156.  
  1157.  
  1158. #     Help system which private notices a help menu to people who type !help in the channel.
  1159.  
  1160. on -public "* * !help" {
  1161.     ^notice $0 Please type 4/msg $N !help <topic> to receive help on specific topics:
  1162.     ^notice $0 01. General info: copyright, general, start_game
  1163.     ^notice $0 02. Special features: daily_double
  1164.     ^notice $0 03. Stat related: title, title_kill
  1165.     ^notice $0 04. Admin control: add, reset, save, start, stop, sub, wipe
  1166. }
  1167.  
  1168. # General information help system
  1169.  
  1170.  
  1171.  
  1172. #     Respond to trivia answers sent as a regular message. Calls $check_active() to see whether
  1173. #     a question is currently being shown. $check_active() will also filter out commands and
  1174. #     execute them.
  1175.  
  1176. on -public "* *" {
  1177. # in a public handler $0 is the sender, $1 is the channel $2- is the message
  1178.     $handle_public($0 $2-)
  1179. }
  1180.  
  1181. # respond to private messages
  1182. on -msg "* *" {
  1183. # in a private handler $0 is the sender, $1- is the message
  1184.     $handle_private($0 $1-)
  1185. }
  1186.  
  1187. #     Hook to detect changes in nickname so we can update the score database so the points
  1188. #     will move with the person.
  1189. on -channel_nick "* * *" {
  1190.     ^timer 1 /update_name $1 $2
  1191. }
  1192.  
  1193.  
  1194. # this call will start up the script
  1195. trivia
  1196.  
  1197.